package sc.tool.sqlgen.branchinfo.pfs;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;

import sc.prototype.common.ConsoleUtil;

public class SimpleStatistic implements ConsoleUtil {

    HashMap<String, Integer> statistic = new HashMap<String, Integer>();

    public void addStatistic(String key) {
        if (statistic.containsKey(key)) {
            statistic.put(key, statistic.get(key) + 1);
        } else {
            statistic.put(key, 1);
        }
    }

    public void printStatistic() {
        StringBuilder sb = new StringBuilder("统计信息：\n");
        for (Iterator<Entry<String, Integer>> iter = statistic.entrySet().iterator(); iter.hasNext();) {
            Entry<String, Integer> entry = iter.next();
            sb.append("项目[").append(entry.getKey()).append("], 计数[").append(entry.getValue()).append("]\n");
        }
        Console.info("{}", sb.toString());
    }
}
